/* ----------------------------------------------------------------------------------------------------------------------------------------------- /

BackgroundLayer - 类名称
修改许可权限 - 修改人名称

< --- Public Vars ------------------------------------------------------------------------------------------------------------------------------ >

< --- Public Functions ------------------------------------------------------------------------------------------------------------------------ >

※ 构造函数
public function BackgroundLayer()

/ ----------------------------------------------------------------------------------------------------------------------------------------------- */
package editor.map{
	import com.OpenFile;
	
	import editor.manager.MapManger;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filesystem.File;
	import flash.net.URLRequest;
	
	public class BackgroundLayer extends Sprite{
		
		// --- Vars ------------------------------------------------------------------------------------------------------------------------------- //
		
		// --- Functions ------------------------------------------------------------------------------------------------------------------------- //
		
		// 构造函数
		public function BackgroundLayer()
		{
			
		}
		
		/**
		 * 改变背景图
		 * @param file 
		 */		
		public function changeBackground(file:File):void
		{
			var loader:Loader = new Loader();
			loader.load(new URLRequest(file.nativePath));
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onBackgroundLoaded);
		}
		
		private function onBackgroundLoaded(evt:Event):void
		{
			var loader:Loader = evt.target.loader;
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onBackgroundLoaded);
			
			var bmp:BitmapData = Bitmap(loader.content).bitmapData;
			this.graphics.clear();
			this.graphics.beginBitmapFill(bmp);
			this.graphics.drawRect(0, 0, bmp.width, bmp.height);
			this.graphics.endFill();
			
			MapManger.getInstance().tileLayer.drawTiles(this.width, this.height);
		}
		//
	}
}